//
//  MainDiscernSelectWatchVC.m
//  ZITHER
//
//  Created by weixin on 2018/11/27.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MainDiscernSelectWatchVC.h"
#import "MainDiscernSelectWatchTbv.h"
#import "MainDiscernDoneVC.h"
#import "CRBRotateBoxCustomChooseManage.h"

@interface MainDiscernSelectWatchVC ()

@property (nonatomic,strong)MainDiscernSelectWatchTbv * tbv;

@property (nonatomic,strong)BaseBtn * btn;

@end

@implementation MainDiscernSelectWatchVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNav];
    [self setUI];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tbv reloadData];
}
  -(void)setNav{
    [self.baseNavigationView setHiddenNav:NO VC:self];
    [self.baseNavigationView NavigationBarStyle:1];
    self.baseNavigationView.navViewStyle.title.text = @"选择表款";
//    self.baseNavigationView.navViewStyle.leftBtn.hidden = YES;
    self.baseNavigationView.leftButton1.hidden = YES;
    
}

-(void)setUI{
    
    [self.view addSubview:self.tbv];
    
    [self.view addSubview:self.btn];
    
    [self.tbv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(NaviHeight);
        make.left.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(kScreenH-NaviHeight);
    }];
    
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-kBottomSafeHeight-20);
        make.left.equalTo(self.view).offset(15);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(45);
    }];
}

- (MainDiscernSelectWatchTbv *)tbv{
    if (!_tbv) {
        _tbv = [[MainDiscernSelectWatchTbv alloc]initializeFrame:CGRectMake(0, 0, 1, 1) isMj:0 isEstimatedRowHeight:YES addRegisterNib:@[@"MainDiscernTbvCellPic",@"MainDefaulSearchTypeOne_V4_Cell",@"MainDefaulSearchTypeTwo_V4_Cell"]];
    }
    return _tbv;
}

-(BaseBtn *)btn{
    if (!_btn) {
        _btn = [[BaseBtn alloc]initializeFrame:CGRectMake(0, 0, 1, 1) NormalText:@"确认提交" NormalTextColor:baseColorTheme SeleText:@"" SeleTextColor:baseColorTheme  font:15 isBold:NO];
        [_btn setCornerRadiusWithRadius:4 isMasks:YES];
        [_btn setBorderWithColor:baseColorTheme width:1];
        /** 按钮点击案例 */
        @weakify(self);
        [[_btn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);

            [self done];
            
        }];
    }
    return _btn;
}


-(void)done{
    CRBRotateBoxCustomChooseManage *modelManage = [CRBRotateBoxCustomChooseManage shareManager];

//    letterModel *model = self.tbv.arrM[0];
//    MainDiscernSelectWatchSeriesModelSub *model2 = self.tbv.arrM[1];
    goodVOsModel *model3 =  self.tbv.arrM[2];
    

    

//    NSString *str
//    modelManage.brandInfoModel
    NSString *goodId = @"";
    NSString *seriesId = @"";
    NSString *brandId = @"";
    NSString *goodName = @"";
    NSString *seriesName = @"";
    NSString *brandName = @"";
    
    brandId = modelManage.brandInfoModel.id;
    brandName = modelManage.brandInfoModel.brandNameNative;
    
    if (modelManage.customGoodsName.length ==0) {
        goodId = modelManage.goodsInfoModel.goodInfo.id;
        goodName = modelManage.goodsInfoModel.goodInfo.goodNameNative;
    }else{
        goodName = modelManage.customGoodsName;
    }
    
    if (modelManage.customSeriesName.length ==0) {
        seriesId = modelManage.seriesInfoModel.id;
        seriesName = modelManage.seriesInfoModel.seriesNameNative;
    }else{
        seriesName = modelManage.customSeriesName;
    }
    
    
//    if (self.videoID.length==0||self.id.length == 0) {
//        [Tools showTips:@"返回上一步重新上传"];
//        return;
//    }
    
    if (brandId.length == 0) {
        [Tools showTips:@"品牌为空"];
        return ;
    }else if (seriesName.length == 0){
        [Tools showTips:@"系列为空"];
        return ;
    }else if (goodName.length == 0){
        [Tools showTips:@"型号为空"];
        return ;
    }
    
    
//    goodId = [goodId isEqualToString:@"其他"]?@"":goodId;
//    seriesId = [goodId isEqualToString:@"其他"]?@"":seriesId;
//    brandId = [goodId isEqualToString:@"其他"]?@"":brandId;
//    goodName = [goodId isEqualToString:@"其他"]?@"":goodName;
//    seriesName = [goodId isEqualToString:@"其他"]?@"":seriesName;
//    brandName = [goodId isEqualToString:@"其他"]?@"":brandName;

    
    [[serviceDefualt loadVideosaveVideoId:self.videoID id:self.id goodId:goodId seriesId:seriesId brandId:brandId goodName:goodName seriesName:seriesName brandName:brandName reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
        if (x.success) {
            [Tools showTips:@"上传腕表视频信息成功"];
            MainDiscernDoneVC *vc = [[MainDiscernDoneVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [Tools showTips:@"上传腕表视频信息失败"];
        }
    }];

}



@end
